<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">甲方标签库</ui:define>
    <ui:define name="content">
        <h:form>
            <p:defaultCommand target="search"/>
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton value="批量模式"
                                         icon="fa fa-list-ul"
                                         actionListener="#{loanProductListBean.changeModeToBatch}"
                                         update="@form"
                                         process="@this"
                                         rendered="#{loanProductListBean.isNotBatch()}"/>
                        <p:commandButton value="常规模式" icon="fa fa-file"
                                         actionListener="#{loanProductListBean.changeModeToNormal}"
                                         process="@this"
                                         update="@form"
                                         rendered="#{loanProductListBean.isBatch()}"/>
                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"
                                         rendered="#{security:areAllGranted('LOAN_FAMILY_TAGS_FIRST_PARTY_SEARCH')}"/>
                        <p:commandButton value="导入更新" icon="fa fa-upload" action="#{loanProductListBean.onImport}">
                            <f:setPropertyActionListener
                                    value="/views/product/product/list.xhtml"
                                    target="#{currentUserBean.back}"/>
                        </p:commandButton>
                        <p:columnToggler datasource="productInfoDataTable" trigger="toggler"
                                         rendered="#{security:areAllGranted('LOAN_FAMILY_TAGS_FIRST_PARTY_SEARCH')}"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         actionListener="#{loanProductListBean.onSearch}"
                                         update="@form"
                                         rendered="#{loanProductListBean.isNormal() and security:areAllGranted('LOAN_FAMILY_TAGS_FIRST_PARTY_SEARCH')}"/>
                        <p:commandButton value="重置" icon="fa fa-refresh"
                                         actionListener="#{loanProductListBean.onReset}"
                                         process="@this"
                                         update="@form"
                                         rendered="#{loanProductListBean.isNormal() and security:areAllGranted('LOAN_FAMILY_TAGS_FIRST_PARTY_SEARCH')}"/>
                        <p:commandButton value="上线" icon="fa fa-arrow-up"
                                         actionListener="#{loanProductListBean.onBatchOnline}"
                                         update="@form"
                                         rendered="#{loanProductListBean.isBatch() and security:areAllGranted('LOAN_FAMILY_TAGS_FIRST_PARTY_ONLINE')}"/>
                        <p:commandButton value="下线" icon="fa fa-arrow-down"
                                         actionListener="#{loanProductListBean.onBatchOffline}"
                                         update="@form"
                                         rendered="#{loanProductListBean.isBatch() and security:areAllGranted('LOAN_FAMILY_TAGS_FIRST_PARTY_OFFLINE')}"/>
                        <p:commandButton value="导出" icon="fa fa-download"
                                         rendered="#{loanProductListBean.isBatch() and security:areAllGranted('LOAN_FAMILY_TAGS_FIRST_PARTY_SEARCH,LOAN_FAMILY_TAGS_FIRST_PARTY_EXPORT')}">
                            <p:dataExporter type="xls" target="productInfoDataTable" fileName="export"/>
                        </p:commandButton>
                        <p:commandButton icon="fa fa-plus" value="新增"
                                         action="#{loanProductListBean.onAdd}"
                                         rendered="#{loanProductListBean.isNormal() and security:areAllGranted('LOAN_FAMILY_TAGS_FIRST_PARTY_ADD')}">
                            <f:setPropertyActionListener value="/views/product/product/list.xhtml"
                                                         target="#{currentUserBean.back}"/>
                        </p:commandButton>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <div class="ui-g">
                    <div class="ui-g-12">
                        <div class="card">
                            <h1>查询条件</h1>
                            <p:panelGrid columns="4" layout="grid"
                                         columnClasses="ui-grid-col-1,ui-grid-col-5,ui-grid-col-1,ui-grid-col-5"
                                         styleClass="ui-panelgrid-blank"
                                         style="border:0px none; background-color:transparent;">

                                <p:outputLabel for="name" value="活动名称"/>
                                <p:inputText id="name" value="#{loanProductListBean.$.name}"/>

                                <p:outputLabel for="activityId" value="活动ID"/>
                                <p:inputNumber id="activityId" value="#{loanProductListBean.$.activityId}"
                                               decimalPlaces="0"/>

                                <p:outputLabel for="status" value="状态"/>
                                <p:selectOneButton id="status" value="#{loanProductListBean.$.status}">
                                    <f:selectItems
                                            value="#{loanProductListBean.dictionaries[DictionaryCode.ONLINE_OFFLINE_STATUS]}"
                                            var="dic"
                                            itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                </p:selectOneButton>

                                <p:outputLabel for="autoOnline" value="自动上线"/>
                                <p:selectOneButton id="autoOnline" value="#{loanProductListBean.$.autoOnline}">
                                    <f:selectItem itemValue="1" itemLabel="是"/>
                                    <f:selectItem itemValue="0" itemLabel="否"/>
                                </p:selectOneButton>

                                <p:outputLabel for="recommendPoolType" value="推荐池类型"/>
                                <p:selectOneMenu id="recommendPoolType" value="#{loanProductListBean.$.alternate}">
                                    <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                                  noSelectionOption="true"/>
                                    <f:selectItems
                                            value="#{loanProductListBean.dictionaries[DictionaryCode.RECOMMEND_POOL_TYPE]}"
                                            var="dic"
                                            itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                </p:selectOneMenu>

                                <p:outputLabel for="parentPrdid" value="所属大产品"/>
                                <p:selectOneMenu id="parentPrdid"
                                                 value="#{loanProductListBean.$.parentPrdid}" filter="true"
                                                 filterMatchMode="contains">
                                    <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                                  noSelectionOption="true"/>
                                    <f:selectItems value="#{loanProductListBean.dictionaries[DictionaryCode.LARGE_COMMON_PRODUCT]}"
                                                   var="dic"
                                                   itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                </p:selectOneMenu>

                            </p:panelGrid>
                        </div>
                        <div class="card">
                            <p:dataTable id="productInfoDataTable"
                                         style="width: 100%"
                                         var="productInfo"
                                         value="#{loanProductListBean.lazyDataModel}"
                                         rows="#{constants:get('ROWS')}"
                                         lazy="true"
                                         paginator="true"
                                         paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                         rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                         emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                         scrollable="true"
                                         scrollWidth="97%"
                                         reflow="true"
                                         selection="#{loanProductListBean.selectedRecords}"
                                         resizableColumns="true"
                                         rendered="#{security:areAllGranted('LOAN_FAMILY_TAGS_FIRST_PARTY_SEARCH')}">


                                <p:column headerText="操作" rendered="#{loanProductListBean.isNotBatch()}">
                                    <p:splitButton icon="fa fa-eye"
                                                   action="#{loanProductListBean.onEdit(productInfo.id)}"
                                                   process="@this">
                                        <f:setPropertyActionListener
                                                value="/views/product/product/list.xhtml"
                                                target="#{currentUserBean.back}"/>
                                        <p:menuitem value="上线" icon="fa fa-arrow-up"
                                                    action="#{loanProductListBean.onOnline(productInfo.id)}"
                                                    process="@this" update="@form"
                                                    rendered="#{productInfo.status == 0 and security:areAllGranted('LOAN_FAMILY_TAGS_FIRST_PARTY_ONLINE')}"/>
                                        <p:menuitem value="下线" icon="fa fa-arrow-down"
                                                    actionListener="#{loanProductListBean.onOffline(productInfo.id)}"
                                                    process="@this" update="@form"
                                                    rendered="#{productInfo.status == 1 and security:areAllGranted('LOAN_FAMILY_TAGS_FIRST_PARTY_OFFLINE')}"/>
                                        <p:menuitem value="删除" icon="fa fa-fw fa-remove"
                                                    actionListener="#{loanProductListBean.onDelete(productInfo.id)}"
                                                    rendered="#{security:areAllGranted('LOAN_FAMILY_TAGS_FIRST_PARTY_DELETE')}"
                                                    process="@this" update="@form">
                                            <p:confirm header="提示信息" message="是否确定删除?" icon="ui-icon-alert"/>
                                        </p:menuitem>
                                    </p:splitButton>
                                </p:column>
                                <p:column selectionMode="multiple" style="width:16px;text-align:center"
                                          rendered="#{loanProductListBean.isBatch()}"/>
                                <p:column headerText="所属大产品">
                                    <h:outputText value="#{productInfo.large_products}"/>
                                </p:column>
                                <p:column headerText="类型">
                                    <h:outputText value="#{productInfo.type}"/>
                                </p:column>
                                <p:column headerText="ID">
                                    <h:outputText value="#{productInfo.id}"/>
                                </p:column>
                                <p:column headerText="甲方名称">
                                    <h:outputText value="#{productInfo.name}"/>
                                </p:column>
                                <p:column headerText="甲方icon">
                                    <p:graphicImage url="#{productInfo.logo}" width="50px"/>
                                </p:column>
                                <p:column
                                        headerText="控量数(#{loanProductListBean.totalDailyClickUvLimitation})">
                                    <h:outputText
                                            value="#{productInfo.dailyClickUvLimitation == null ?'否': productInfo.dailyClickUvLimitation}"/>
                                </p:column>
                                <p:column
                                        headerText="剩余量(#{loanProductListBean.totalDailyClickUvRemainingOnline})">
                                    <h:outputText style="font-weight: bold; color: red"
                                                  value="#{productInfo.dailyClickUvRemaining}"
                                                  rendered="#{productInfo.dailyClickUvRemaining le 0}"/>
                                    <h:outputText style="font-weight: bold; color: #e0b100"
                                                  value="#{productInfo.dailyClickUvRemaining}"
                                                  rendered="#{productInfo.dailyClickUvRemaining gt 0 and productInfo.dailyClickUvRemaining le (productInfo.dailyClickUvLimitation / 3)}"/>
                                    <h:outputText style="font-weight: bold; color: green"
                                                  value="#{productInfo.dailyClickUvRemaining}"
                                                  rendered="#{productInfo.dailyClickUvRemaining gt 0 and productInfo.dailyClickUvRemaining gt (productInfo.dailyClickUvLimitation / 3)}"/>
                                </p:column>
                                <p:column headerText="自动上线(#{loanProductListBean.totalAutoOnline})">
                                    <h:outputText style="font-weight: bold; color: red" value="否"
                                                  rendered="#{productInfo.productAutoOnlineTimeDisplay == null || productInfo.productAutoOnlineTimeDisplay == ''}"/>
                                    <h:outputText style="font-weight: bold; color: green" value="是"
                                                  rendered="#{productInfo.productAutoOnlineTimeDisplay != null and productInfo.productAutoOnlineTimeDisplay != ''}"/>
                                    <!--<h:outputText style="font-weight: bold; color: red" value="#{productInfo.autoOnlineTime}"/>-->

                                </p:column>
                                <p:column headerText="自动上线时间">
                                    <h:outputText value="#{productInfo.productAutoOnlineTimeDisplay}">
                                        <f:convertDateTime pattern="HH:mm"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="状态(#{loanProductListBean.totalOnline})">
                                    <h:outputText style="font-weight: bold; color: red" value="下线"
                                                  rendered="#{productInfo.status == 0}"/>
                                    <h:outputText style="font-weight: bold; color: green" value="上线"
                                                  rendered="#{productInfo.status == 1}"/>
                                </p:column>
                                <p:column headerText="最后更新人">
                                    <h:outputText value="#{productInfo.updator}"/>
                                </p:column>
                                <p:column headerText="更新时间">
                                    <h:outputText value="#{productInfo.updateTime}">
                                        <f:convertDateTime pattern="#{constants:get('DATETIME_FORMAT')}"/>
                                    </h:outputText>
                                </p:column>
                            </p:dataTable>
                        </div>
                    </div>
                </div>
            </div>
        </h:form>
    </ui:define>
</ui:composition>
